/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package plash.display;

import plash.utils.ColorMapper;
import processing.core.PGraphics;

/**
 *
 * @author User
 */
public class GraphicFill implements IGraphicCommand
{

    private Graphics _g;
    private PGraphics _painter;
    private float _alpha;
    private ColorMapper _cmapper;

    public GraphicFill(Graphics g, int rgb, float alpha)
    {
        _g = g;
        _painter = g.getPainter();
        _cmapper = new ColorMapper(alpha, rgb);
        _alpha = alpha;
    }

    @Override
    public void execute()
    {
        if (_g == null)
        {
            return;
        }
        if (_painter == null)
        {
            _painter = _g.getPainter();
        }

        if (_cmapper.getAlpha() == 0)
        {
            _painter.noFill();
            return;
        }

        _g.getOwner().getPainter().fill(_cmapper.getRed(), _cmapper.getGreen(), _cmapper.getBlue(), _cmapper.getAlpha() * _g.getOwner().getAlpha());
       
    }
}

/**
 * if (_g.getOwner().isIsMasker())
            {
                _g.getOwner().getMaskPainter().fill(
                        255, 
                        255, 
                        255, 
                        255);
            }
            else
            {
                _g.getOwner().getMaskPainter().fill(
                        _cmapper.getRed(), 
                        _cmapper.getGreen(), 
                        _cmapper.getBlue(), 
                        _cmapper.getAlpha() * _g.getOwner().getAlpha());
            }
 */